{extend name="common/block" /}
{block name="content"}
<div class="layui-btn-container " style="display: inline-block;">
    {if array_key_exists('delete',$menu_buttons)}
    <button id="btnDeleteChecked" class="layui-btn layui-btn-sm layui-btn-danger" j-href="{:url($menu_buttons.delete.link)}">
        <i class="layui-icon">{if !empty($menu_buttons.delete.icon)}$menu_buttons.delete.icon{else/}&#xe640;{/if}</i>{$menu_buttons.delete.name}
    </button>
    {/if}
    {if isset($menu_buttons.create)}
    <button class="layui-btn layui-btn-sm j-open"
            j-href="{:url($menu_buttons.create.link)}"
            j-title="{$menu_buttons.create.name}"
            j-type="2"
            j-config='{"area":["80%","80%"],"anim":2}'
    >
        <i class="layui-icon">{if !empty($menu_buttons.create.icon)}$menu_buttons.create.icon{else/}&#xe640;{/if}</i>{$menu_buttons.create.name}
    </button>
    {/if}

</div>

{if isset($menu_buttons.search)}
<div class="j-right">
    <input class="layui-input" id="edtSearch" value="" placeholder="输入关键字,菜单名等"
           style="display: inline-block;width: 140px;height: 30px;line-height: 30px;padding: 0 5px;margin-right: 5px;"/>
    <div class="layui-btn-container" style="display: inline-block;">
        <button id="btnSearch" class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe615;</i>搜索
        </button>
        <button id="btnClearSearch" class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#x1006;</i>清除搜索
        </button>
    </div>
</div>
{/if}

<script type="text/html" id="opera">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<table id="table" lay-filter="Log"></table>
{/block}

{block name="script"}
<script>
    layui.use(['table', 'layer', 'jquery'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery;

        table.render({
            elem: '#table',
            url: '{:url("index")}',
            page: true,
            height: 'full-200',
            method:'post',
            toolbar: true,
            cols: [[ //表头
                {type:'checkbox'}
                , {field:'account',title :'操作人'}
                , {field:'name',title:'操作名'}
                , {field:'path_info',title:'地址'}
                , {field:'method',title:'请求方式'}
                , {field:'query',title:'参数'}
                , {field:'ip',title:'访问ip'}
                , {field:'num',title:'访问统计'}
                , {field:'createtime',title:'最近访问时间'}
            ]],
        })
        
         table.on('tool(Log)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定执行删除操作', function(index){
                    layer.close(index);
                    $.get('delete', {id:data.id},function(r){
                        if(r.code == 1){
                            showpopup(r.msg);
                            obj.del();
                        }else{
                            showpopup(r.msg);
                        }
                    },'json')
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type:2,
                    content:'update?id='+data.id,
                    shadeClose:true,
                    area:['80%','80%'],
                })
            }
        });
})
</script>
{/block}
